package com.itheima.sfbx.insurance.handler.impl;

import com.itheima.sfbx.framework.commons.constant.insure.InsureConstant;
import com.itheima.sfbx.insurance.dto.CustomerRelationVO;
import com.itheima.sfbx.insurance.dto.DoInsureVo;
import com.itheima.sfbx.insurance.handler.InsureHandler;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @ClassName AccidentInsureHandler.java
 * @Description 保障型意外类：保险投保、创建订单、保费计算
 */
@Service
public class AccidentInsureHandler extends SafeguardInsureHandler implements InsureHandler {
    @Override
    public String doPremium(DoInsureVo doInsureVo) {
//        查询被投保人
        CustomerRelationVO insured = insureProcessHandler.buildInsured(doInsureVo.getCustomerRelationIds().get(0));
        if (insured != null){
//            获取收入情况
            BigDecimal income = insured.getIncome();
//            判断收入是否有问题,收入为null或者大于100w的话就抛出异常
            if (income == null || income.compareTo(BigDecimal.valueOf(100000)) > 0){
                throw new RuntimeException("收入异常");
            }
        }
        return super.doPremium(doInsureVo);
    }
}
